package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.system.dto.PmProDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.system.domain.PmPro;
import com.inspur.system.service.IPmProService;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 【项目】Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/pro")
public class PmProController extends BaseController
{
    @Autowired
    private IPmProService pmProService;

    /**
     * 查询【项目】列表
     */
    @PreAuthorize("@ss.hasPermi('system:pro:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmProDTO pmPro)
    {
        startPage();
        List<PmProDTO> list = pmProService.selectPmProList(pmPro);
        return getDataTable(list);
    }

    /**
     * 查询项目数量
     */
    @PreAuthorize("@ss.hasPermi('system:pro:listnum')")
    @GetMapping("/listNum")
    public AjaxResult listNum()
    {
        return success(pmProService.selectPmProNum());
    }

    /**
     * 查询项目工作项数量
     */
    @PreAuthorize("@ss.hasPermi('system:pro:listworknum')")
    @GetMapping("/listWorkNum/{cProNo}")
    public AjaxResult listWorkNum(@PathVariable("cProNo") String cProNo)
    {
        return success(pmProService.selectPmProWorkNum(cProNo));
    }

    /**
     * 查询项目工作项工时
     */
    @PreAuthorize("@ss.hasPermi('system:pro:listworknum')")
    @GetMapping("/listWorkTime/{cProNo}")
    public AjaxResult listWorkTime(@PathVariable("cProNo") String cProNo)
    {
        return success(pmProService.selectPmProWorkTime(cProNo));
    }

    /**
     * 查询项目名称列表
     */
    @PreAuthorize("@ss.hasPermi('system:pro:listname')")
    @PostMapping("/listName")
    public AjaxResult listName(@RequestParam String cProNo)
    {
        return success(pmProService.selectPmProName(cProNo));
    }

    /**
     * 查询燃尽图
     */
    @PreAuthorize("@ss.hasPermi('system:pro:listworkechars')")
    @GetMapping("/listWorkEchars/{cProNo}")
    public AjaxResult listWorkEchars(@PathVariable("cProNo") String cProNo)
    {
        return success(pmProService.selectPmProWorkEchars(cProNo));
    }

    /**
     * 导出【项目】列表
     */
    @PreAuthorize("@ss.hasPermi('system:pro:export')")
    @Log(title = "【导出项目列表】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmPro pmPro)
    {
        List<PmPro> list = pmProService.selectPmProListExport(pmPro);
        ExcelUtil<PmPro> util = new ExcelUtil<PmPro>(PmPro.class);
        util.exportExcel(response, list, "导出数据");
    }

    /**
     * 获取【项目】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pro:query')")
    @GetMapping(value = "/{cProNo}")
    public AjaxResult getInfo(@PathVariable("cProNo") String cProNo)
    {
        return success(pmProService.selectPmProByCProNo(cProNo));
    }

    /**
     * 新增【项目】
     */
    @PreAuthorize("@ss.hasPermi('system:pro:add')")
    @Log(title = "新增项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmPro pmPro)
    {
        return toAjax(pmProService.insertPmPro(pmPro));
    }

    /**
     * 修改【项目】
     */
    @PreAuthorize("@ss.hasPermi('system:pro:edit')")
    @Log(title = "修改项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmPro pmPro)
    {
        return toAjax(pmProService.updatePmPro(pmPro));
    }

    /**
     * 删除【项目】
     */
    @PreAuthorize("@ss.hasPermi('system:pro:remove')")
    @Log(title = "删除项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cProNos}")
    public AjaxResult remove(@PathVariable String[] cProNos)
    {
        return toAjax(pmProService.deletePmProByCProNos(cProNos));
    }
}
